package interview.sortingandsearching;

public class ArrayMerge {
	public void merge(int[] arrayA, int[] arrayB, int sizeA) {
		int index = sizeA + arrayB.length - 1;
		int ptrA = sizeA - 1;
		int ptrB = arrayB.length - 1;

		while(ptrA >= 0 && ptrB >= 0) {
			if(arrayA[ptrA] > arrayB[ptrB]) {
				arrayA[index] = arrayA[ptrA];
				index--;
				ptrA--;
			} else {
				arrayA[index] = arrayB[ptrB];
				index--;
				ptrB--;
			}
		}

		while(ptrB > 0) {
			arrayA[index] = arrayB[ptrB];
			ptrB--;
		}
	}
}
